<template>
  <div class="container">
    <leftcont></leftcont>
    <div class="righCont">
      <topcont></topcont>
      <div class="cardCont">
        <div class="carItem">
          <div class="carName">总金额</div>
          <div class="carText">{{ headData.sum_total }}元</div>
        </div>
        <div class="carItem">
          <div class="carName">程序员会员</div>
          <div class="carText">{{ headData.cv_member_money }}元</div>
        </div>
        <div class="carItem">
          <div class="carName">雇主会员</div>
          <div class="carText">{{ headData.enterprise_member_money }}元</div>
        </div>
        <div class="carItem">
          <div class="carName">联系套餐</div>
          <div class="carText">{{ headData.cs_total_money }}元</div>
        </div>
      </div>
      <div class="content">
        <div class="payTable">
          <div class="trendTop">
            <div>收益列表({{ total }})</div>
          </div>
          <div class="tableCont">
            <div class="tableSerchCont">
              <div class="serchItem">
                <el-date-picker
                  v-model="serchTime"
                  type="daterange"
                  align="right"
                  unlink-panels
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :picker-options="pickerOptions"
                >
                </el-date-picker>
              </div>
              <div class="serchItem" style="width: 200px">
                <el-select v-model="order_status" placeholder="请选择类型">
                  <el-option
                    v-for="(item, index) in navArr"
                    :key="index"
                    :label="item.val"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="serchItem" style="width: 200px">
                <el-input
                  v-model="order_number"
                  placeholder="请输入订单号"
                ></el-input>
              </div>
              <div class="serchItem">
                <btn @click="serchFn" value="搜索"></btn>
              </div>
            </div>
            <el-table :data="orderList" style="width: 100%">
              <el-table-column
                prop="order_number"
                width="200"
                show-overflow-tooltip
                label="订单号"
              >
              </el-table-column>
              <el-table-column
                prop="nick_name"
                show-overflow-tooltip
                label="充值账号"
              >
              </el-table-column>
              <el-table-column show-overflow-tooltip label="充值内容">
                <template #default="scope">
                  <span v-if="scope.row.type == 1"
                    >{{ scope.row.remark }}次联系套餐</span
                  >
                  <span v-if="scope.row.type == 2"
                    >{{ scope.row.remark }}个月会员</span
                  >
                </template>
              </el-table-column>
              <el-table-column
                prop="pay_money"
                show-overflow-tooltip
                label="支付金额"
              >
              </el-table-column>
              <el-table-column
                prop="pay_time"
                show-overflow-tooltip
                label="支付时间"
              >
              </el-table-column>
            </el-table>
            <div class="pageCont">
              <el-pagination
                background
                layout="prev, pager, next"
                :page-size="per_page"
                @current-change="pageFn"
                :current-page="page"
                :total="total"
              >
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import leftcont from "@/components/leftCont.vue";
import topcont from "@/components/topCont.vue";
import btn from "@/components/public/btn.vue";
import { Recharge, statistics } from "@/http/api";
import { ElMessage, ElMessageBox } from "element-plus";

export default {
  components: { leftcont, topcont, btn },
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      orderList: [],
      headData: "",
      serchTime: "",
      order_number: "",
      page: 1,
      per_page: 5,
      total: 0,
      showLoad: false,
      navArr: [
        { val: "全部", id: "" },
        { val: "程序员", id: 1 },
        { val: "企业", id: 2 },
      ],
      order_status: "",
    };
  },
  props: {},
  methods: {
    getTime(time) {
      let n = time.getFullYear();
      let y = time.getMonth() + 1;
      let d = time.getDate();
      let timeStr = n + "-" + y + "-" + d;
      return timeStr;
    },
    toDetailFn(item) {
      this.$router.push({
        path: "/userCenterOrderDetail",
        query: { id: item.order_id },
      });
    },
    pageFn(index) {
      this.page = index;
      this.getData();
    },
    serchFn() {
      this.orderList = [];
      this.page = 1;
      this.getData();
    },
    getData() {
      let time = "";
      if (this.serchTime != null && this.serchTime.length > 0) {
        time =
          this.getTime(this.serchTime[0]) +
          "," +
          this.getTime(this.serchTime[1]);
      }
      let data = {
        order_number: this.order_number,
        type: this.order_status,
        per_page: this.per_page,
        page: this.page,
        time: time,
      };
      Recharge(data)
        .then((res) => {
          if (res.data.code == 1) {
            this.orderList = res.data.data.data;
            this.total = res.data.data.total;
          } else {
            ElMessage(res.data.msg);
          }
        })
        .catch((err) => {
          ElMessage("服务器请求超时");
        });
    },
    getTotalMoney() {
      statistics().then((res) => {
        this.headData = res.data.data;
      });
    },
  },
  mounted() {},
  created() {
    this.getData();
    this.getTotalMoney();
  },
};
</script>

<style scoped lang="less">
.container {
  width: 100%;
  height: 100vh;
  display: flex;
  overflow: hidden;
  .righCont {
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-left: 15px;
    height: 100%;
    width: 10px;
    background-color: #f4f8ff;
    .cardCont {
      padding: 15px 20px;
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      .carItem {
        width: 22%;
        background-color: #fff;
        border-radius: 5px;
        padding: 15px;
        box-sizing: border-box;
        .carName {
        }
        .carText {
          margin-top: 5px;
          font-weight: bold;
          font-size: 20px;
        }
      }
    }
    .content {
      padding: 20px;
      padding-top: 0px;
      box-sizing: border-box;
      width: 100%;
      flex: 1;
      overflow: auto;
      .payTable {
        width: 100%;
        background-color: #fff;
        padding: 15px;
        box-sizing: border-box;
        border-radius: 5px;
        .trendTop {
          font-weight: bold;
          font-size: 16px;
          cursor: pointer;
        }
        .tableCont {
          width: 100%;
          margin-top: 15px;
          .tableSerchCont {
            width: 100%;
            display: flex;
            justify-content: flex-end;
            margin-bottom: 10px;
            .serchItem {
              margin-left: 10px;
            }
          }
          .ctrolBtn {
            display: flex;
            .text_btn {
              margin: 0 5px;
              cursor: pointer;
              font-size: 14px;
            }
            .balckBtn {
              color: #666;
            }
            .redBtn {
              color: #f56c6c;
            }
            .blueBtn {
              color: #96a1fe;
            }
            .greenBtn {
              color: #85ce61;
            }
          }
          .pageCont {
            padding: 30px 0;
            display: flex;
            justify-content: center;
          }
        }
      }
    }
  }
}
</style>
